<template>
  <div class="centers" style="height: 100%">
    <div class="cardHeader flex">
      <div
          @click="onBack"
          style="display: flex; align-items: center; cursor: pointer"
      >
        <img
            class="cardHeader_icon m_hoverCP"
            src="../../assets/img/img28.png"
            alt=""
        />{{$t('message.Return')}}
      </div>

<!--      <div class="flex1" v-if="type == 2">
        <a-button
            @click="selectTemplate(1)"
            class="xinzeng"
            :disabled="newForm.status == 1"
        >
          <img class="img" src="../../assets/carbon/img6.png" alt=""/>
          {{$t('message.select_template')}}
        </a-button
        >
        <a-button
            @click="onModels"
            class="leftChaxun"
            :disabled="newForm.status == 1"
        >
          <img class="img" src="../../assets/carbon/img.png" alt=""/>
          {{$t('message.save_as_template')}}
        </a-button
        >
      </div>-->
    </div>
    <div class="contentBox" :class="{ paddings: type == 2, scroll: type == 2 }">
      <!-- 左侧树形 -->
      <div class="leftTree">
        <div class="select">
          <a-select
              style="width: 240px"
              v-model="form.codesName"
              :disabled="queryId != '' || newForm.status == 1"
              @change="updateProvince"
          >
            <a-select-option
                v-for="(province, index) in provinceData"
                :key="index"
            >
              {{ province.title }}
            </a-select-option>
          </a-select>
        </div>
        <a-anchor
            v-if="treeData && treeData.length > 0"
            :getContainer="getContainer"
            :affix="false"
            @click="handleAnchorCliack"
        >
          <a-tree :tree-data="treeData" :defaultExpandAll="true">
            <template #title="{ key: treeKey, title }">
              <a-anchor-link :href="treeKey" :title="title">
              </a-anchor-link>
            </template>
          </a-tree>
        </a-anchor>
      </div>
      <div class="rightTree" id="risgtUd" :class="{ scroll: type == 2 }">
        <div class="table-page-tpyzd top" :class="{ posts: type == 2 }">
          <a-form-model
              layout="inline"
              :model="form"
              ref="ruleForm"
              :rules="rules"
              v-if="type == 1"
          >
            <a-row :gutter="24">
              <a-col :md="6" :sm="8">
                <a-form-model-item :label="$t('message.template_name')" prop="name">
                  <a-input :placeholder="$t('message.Please_enter')" v-model="form.name"/>
                </a-form-model-item>
              </a-col>
              <a-col :md="6" :sm="8">
                <a-form-model-item :label="$t('message.Industry')">
                  <a-select style="width: 100%" v-model="form.profession">
                    <a-select-option
                        v-for="province in professionData"
                        :key="province.key"
                    >
                      {{ province.title }}
                    </a-select-option>
                  </a-select>
                </a-form-model-item>
              </a-col>
              <span
                  style="float: right; overflow: hidden"
                  class="table-page-search-submitButtons"
              >
                <a-col :md="6" :sm="24">
                  <a-button @click="saveTemplate" class="leftChaxun">
                    <img class="img" src="../../assets/carbon/img.png" alt=""/>
                    {{$t('message.save_as_template')}}</a-button>
                </a-col>
              </span>
            </a-row>
          </a-form-model>
          <a-form layout="inline" v-if="type == 2">
            <a-row :gutter="24">
              <a-col :md="6" :sm="8">
                <a-form-item :label="$t('message.Accounting_entity')">
                  <a-select
                      style="width: 100%"
                      v-model="form.targetId"
                      :disabled="newForm.status == 1"
                  >
                    <a-select-option
                        v-for="province in CostCalcArr"
                        :key="province.id"
                        :value="province.id"
                    >
                      {{ province.departName }}
                    </a-select-option>
                  </a-select>
                </a-form-item>
              </a-col>
              <a-col :md="6" :sm="8">
                <a-form-item :label="$t('message.Accounting_date')">
                  <a-date-picker
                      :disabled="newForm.status == 1"
                      v-model="form.year"
                      :format="monthFormat"
                      mode="year"
                      :open="oprnYerOpen"
                      @panelChange="newFormpanelChange"
                      @openChange="onPrnYerOpenlChange"
                  />
                </a-form-item>
              </a-col>
              <a-col :md="6" :sm="8" v-if = "emissionSourceRowKeys.length>0">
                <div class="ant-alert">
                  {{ $t('message.Selected') }} <a style="font-weight: 600">{{ emissionSourceRowKeys.length }}</a>
                  <a style="margin-left: 18px" @click="onClearEmissionSourceRowKeys">{{ $t('message.clear') }}</a>
                  <a style="margin-left: 18px" @click="deleteBatch">{{ $t('message.Delete') }}</a>
                  <a style="margin-left: 18px" @click="onInviteUserVisible(emissionSourceRowKeys)">{{$t('message.Inviter_to_fill_in')}}</a>
                </div>
              </a-col>
              <span
                  style="float: right; overflow: hidden"
                  class="table-page-search-submitButtons"
              >
                <a-col :md="6" :sm="24">
                  <a-button
                      @click="onRapidFilling"
                      class="leftChaxun"
                      :disabled="newForm.status == 1"
                  >
                    {{$t('message.fill_in_quickly')}}</a-button
                  >
                </a-col>
              </span>
            </a-row>
          </a-form>
        </div>
        <a-spin :spinning="spinning">
          <div class="collapse-tpyz" :class="{ paddTops: type == 2 }">
            <a-collapse v-model="activeKey">
              <a-collapse-panel
                  v-for="(item, idex) in collapseData"
                  :key="item.id"
                  :header="item.name"
                  :id="item.id"
              >
                <div
                    class="collaose-center"
                    v-for="(value, idese) in item.children"
                    :key="idese"
                    :id="value.id"
                >
                  <div class="collaose-title">
                    <img src="../../assets/carbon/img1.png" alt=""/>
                    {{ value.name }}
                  </div>
                  <div class="collapse-table">
                    <a-table
                        :columns="columns"
                        :data-source="value.children"
                        rowKey="id"
                        :row-selection="{ selectedRowKeys: emissionSourceRowKeys, onChange: emissionSourceSelected }"
                        :pagination="false"
                        bordered
                    >
                      <template
                          slot="carbonMolecule"
                          slot-scope="text, record, index"
                      >
                        <div class="editable-row-operations">
                          {{ record.carbonMolecule }}/{{
                            record.carbonDenomintor
                          }}
                        </div>
                      </template>
                      <template slot="dataVoucher" slot-scope="text, record, index">
                        <span v-if="!text" style="font-size: 12px;font-style: italic;">{{$t('No files')}}</span>
                        <a-button
                            v-else
                            :ghost="true"
                            type="primary"
                            icon="download"
                            size="small"
                            @click="downloadFile(text)">
                          {{$t('message.Download')}}
                        </a-button>
                      </template>

                      <template slot="operation" slot-scope="text, record, index">
                          <div style="display: flex; align-items: center;justify-content: center">
                            <a @click="() => onBasicCheckDetailEditVisible(record)" :disabled="newForm.status == 1 || record.informantUserId !=null">
                              {{ $t("message.Edit") }}
                            </a>
                            <a-divider type="vertical" />
                            <a-popconfirm :title="$t('message.Confirm_delete')" :cancelText="$t('message.Cancel')"
                                          :okText="$t('message.Confirm')" :disabled="newForm.status == 1 || record.informantUserId !=null"
                                          @confirm="() => saveDelte(idex, idese, index, record)"
                            >
                              <a :disabled="newForm.status == 1 || record.informantUserId !=null">{{$t('message.Delete')}}</a>
                            </a-popconfirm>
                            <a-divider type="vertical" />
                            <j-upload v-if='!record.dataVoucher'
                                      @change="loadTreeRootTree()"
                                      :text="$t('message.upload_attachment')"
                                      :uploadAction="uploadAction+'?id='+record.id"
                                      :disabled="newForm.status == 1 || record.informantUserId !=null"
                                      :buttonVisible="false" :showUploadList="false" :number="1"></j-upload>
                            <a  @click="onCancelDataVoucher(record.id,null)":disabled="newForm.status == 1 || record.informantUserId !=null" v-else>{{$t('message.delete_attachment')}}</a>
                          </div>
                      </template>

                      <span slot="typeText" slot-scope="text, record, index">
                      {{$t(text == "减排"?'message.reduce_harmful_emissions':"message.Emission")}}
                      </span>

                      <template slot="data" slot-scope="text, record, index">
                        <div class="editable-row-operations">
                          <a-input
                              v-model="record.data"
                              :placeholder="$t('message.Please_enter')"
                              :disabled="newForm.status == 1 || record.informantUserId !=null"
                              @blur="() => saveChange(record)"
                          />
                        </div>
                      </template>
                      <template slot="informant" slot-scope="text, record, index" >
                        <a  :disabled="newForm.status == 1 || record.informantUserId !=null" v-if='!record.informantUserId' @click="onInviteUserVisible([record.id])">
                          {{$t("message.Inviter_to_fill_in")}}
                        </a>
                        <span v-else>
                          <div class="information">
                            <span>
                               {{record.informantUserName}}
                            </span>
                            <img
                                class="cardHeader_icon m_hoverCP"
                                src="@assets/img/img23.png"
                                alt=""
                                @click="onCancelInvite(record.id)"
                                :disabled="newForm.status == 1 || record.informantUserId !=null"
                            />
                          </div>

                        </span>
                      </template>
                    </a-table>
                  </div>
                  <a-button
                      class="collapse-tian"
                      @click="onVsisible(idex, idese, value.children)"
                      :disabled="newForm.status == 1"
                  >
                    <img src="../../assets/carbon/img2.png" alt=""/>
                    {{$t('message.Add_emission_sources')}}
                  </a-button>
                </div>
              </a-collapse-panel>
            </a-collapse>
          </div>
        </a-spin>
      </div>
    </div>
    <!-- 底部数据 -->
    <div class="bottom" v-if="type == 2">
      <div class="flex2">
        <div class="bottom-flex">
          <div class="text">{{$t('message.total_release')}}：</div>
          <div class="text1">{{ carbonObj.total }}</div>
          <div class="text2">tCO₂e</div>
        </div>
        <div class="bottom-flex">
          <div class="text3">{{$t('message.total_energy_carbon_emission')}}：</div>
          <div class="text4">{{ carbonObj.cost }}</div>
          <div class="text5">tCO₂e</div>
        </div>
        <div class="bottom-flex">
          <div class="text3">{{$t('message.reduce_harmful_emissions')}}：</div>
          <div class="text4">{{ carbonObj.green }}</div>
          <div class="text5">tCO₂e</div>
        </div>
      </div>
      <div class="flex1">
        <a-button @click="onDetails" class="xinzeng wigthsP">
          {{$t('message.details_preview')}}
        </a-button
        >
        <a-button
            @click="onAccounting"
            class="leftChaxun wigthsP"
            :disabled="newForm.status == 1"
        >
          {{$t('message.data_accounting')}}
        </a-button
        >
      </div>
    </div>
    <!-- 添加 -->
    <a-drawer
        :visible="visible"
        :title="$t('message.New_emission_source')"
        placement="right"
        :width="800"
        @close="onClose"
    >
      <div>
        <div class="flex marbot">
          <a-input-search
              :placeholder="$t('message.please_enter_a_keyword_such_as_electricity')"
              style="width: 240px"
              v-model="form1.name"
              allowClear
              @search="userPageList(1)"
          />
          <a-button class="xinzeng" @click="onBasicDrawerVisible(1)">
            <img src="../../assets/carbon/img2.png" alt=""/>
            {{$t('message.New_emission_source')}}
          </a-button>
        </div>
        <div>
          <a-table
              :row-selection="{
              selectedRowKeys: selectedRowKeys,
              onChange: onSelectChange,
            }"
              rowKey="id"
              @change="paginationPacheon"
              :columns="columns1"
              bordered
              :data-source="listData1"
              :pagination="pagination1"
          >
            <template slot="carbonMolecule" slot-scope="text, record, index">
              <div class="editable-row-operations">
                {{ record.carbonMolecule }}/{{ record.carbonDenomintor }}
              </div>
            </template>
            <template slot="operation" slot-scope="text, record, index">
              <div class="editable-row-operations">
                <a style="margin-right: 8px" @click="() => saveUpdate(record)">{{$t('message.Detail')}}</a>
              </div>
            </template>
          </a-table>
        </div>
      </div>
      <div
          :style="{
          position: 'absolute',
          bottom: 0,
          width: '100%',
          borderTop: '1px solid #e8e8e8',
          padding: '10px 16px',
          textAlign: 'right',
          left: 0,
          background: '#fff',
          borderRadius: '0 0 4px 4px',
        }"
      >
        <a-button style="margin-right: 8px" @click="onClose"> {{$t('message.Cancel')}}</a-button>
        <a-button type="primary" @click="onSubmit"> {{$t('message.Confirm')}}</a-button>
      </div>
    </a-drawer>

    <a-modal
        v-if="type == 2"
        :title="$t('message.save_template')"
        :visible="visible1"
        @ok="handleOk"
        @cancel="handleCancel"
    >
      <a-form-model :label-col="labelCol" :wrapper-col="wrapperCol">
        <a-form-model-item :label="$t('message.template_name')">
          <a-input
              v-model="FromCheck.standardName"
              :placeholder="$t('message.Please_enter')"
          />
        </a-form-model-item>
        <a-form-model-item :label="$t('message.Industry')">
          <a-select
              style="width: 100%"
              :placeholder="$t('message.Please_select')"
              v-model="FromCheck.profession"
          >
            <a-select-option
                v-for="province in professionData"
                :key="province.key"
            >
              {{ province.title }}
            </a-select-option>
          </a-select>
        </a-form-model-item>
      </a-form-model>
    </a-modal>
    <!--添加的新增详情弹框 -->
    <basicDrawer
        v-if="basicDrawerVisible"
        :addUrl="addUrl"
        :editUrl="editUrl"
        :basicDrawerVisible="basicDrawerVisible"
        :basicDrawerString="basicDrawerString"
        :basicDrawerList="basicDrawerList"
        @onCloseBasicDrawerVisible="onCloseBasicDrawerVisible"
    />

    <basicCheckDetailEditDrawer
        v-if="basicCheckDetailEditVisible"
        :basicDrawerVisible="basicCheckDetailEditVisible"
        :basicDrawerString="basicCheckDetailEditString"
        :basicDrawerList="basicCheckDetailEditDrawerList"
        @onCloseBasicDrawerVisible="onCloseBasicCheckDetailEditVisible"
    />

    <j-select-user-by-dep-modal
        ref="userSelectModal"
        :selectOne="true"
        :departId = "userInfo().departId"
        @ok="selectedUserOk"
        :modal-width="1250"/>

    <a-modal
        v-if="type == 2"
        :title="$t('message.select_template')"
        :visible="visible2"
        @ok="templateHandleOk"
        :width="1144"
        @cancel="handleCancel"
    >
      <div class="marbot">
        <a-input-search
            :placeholder="$t('message.please_enter_a_keyword_such_as_electricity')"
            style="width: 240px"
            v-model="form2.name"
            allowClear
            @search="onSearch"
        />
      </div>
      <a-table
          bordered
          :pagination="pagination2"
          :row-selection="{ selectedRowKeys: selected, onChange: ontChange }"
          :columns="columns2"
          :data-source="data2"
          @change="onChangePage2"
      >
        <template slot="type" slot-scope="text, record, index">
          <div class="editable-row-operations">
            {{ record.type == 2 ? $t('message.my_template') : $t('message.industry_template') }}
          </div>
        </template>
      </a-table>
    </a-modal>

    <section class="m_popupBox" v-if="isShowDetailPopup">
      <rapidFilling
          ref="rapidFilling"
          :examineId="newForm.checkId"
          @onRapoidBack="onRapoidBack"
      ></rapidFilling>
    </section>
    <section class="m_popupBox" v-if="kanbanIsAss">
      <componentsKanban
          ref="kanban"
          :examineId="newForm.checkId"
          :twoType="twoType"
          @onKanbanBack="onKanbanBack"
      ></componentsKanban>
    </section>
  </div>
</template>

<script>


import basicDrawer from '@comp/common/basicDrawer.vue';
import basicCheckDetailEditDrawer from '@comp/common/basicCheckDetailEditDrawer.vue';
import rapidFilling from '@comp/common/rapidFilling.vue';
import componentsKanban from '@comp/common/componentsKanban.vue';
import { getAction, postAction, getFileAccessHttpUrl } from '@api/manage'
import {cloneObject} from "@/utils/util";
import { mapGetters } from 'vuex'
import JSelectUserByDepModal from '@comp/jeecgbiz/modal/JSelectUserByDepModal.vue'

export default {
  name: "TpyzDetail",
  props: {
    addUrl: {
      type: String,
      default: "",
    },
    editUrl: {
      type: String,
      default: "",
    },
    saveUrl: {
      type: String,
      default: "",
    },
    type: {
      type: Number,
      default: 1,
    },
    queryId: {
      type: String,
      default: "",
    },
    newForm: {
      type: Object,
      default: {},
    },
    isCopy: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      uploadAction: window._CONFIG["domianURL"] + "orgCheckCheckDetail/upload",
      informantDetailIds:[],
      spinning: false,
      activeKey: [],
      carbonObj: [],
      twoType: 0,
      kanbanIsAss: false,
      CostCalcArr: [], // 主体
      monthFormat: "YYYY",
      oprnYerOpen: false, // 时间弹窗开关
      labelCol: {
        xs: {span: 24},
        sm: {span: 5},
      },
      wrapperCol: {
        xs: {span: 24},
        sm: {span: 16},
      },
      isShowDetailPopup: false,
      visible: false,
      visible1: false,
      visible2: false,
      collapseData: [],
      selectedRowObje: [],
      valueChildrenIndex: 0,
      valueIndex: 0,
      treeData: [],
      columns: [
        {
          title: this.$t('message.Emission_source'),
          dataIndex: "emissionSourceName",
          align: "center",
        },
        {
          title: this.$t('message.facilities_activities'),
          dataIndex: "activitieName",
          align: "center",
        },
        {
          title: this.$t('message.Emission_type'),
          dataIndex: "typeText",
          align: "center",
          scopedSlots: {customRender: "typeText"},
        },
        {
          title: `CO₂e${this.$t('message.Emission_factor_value')}`,
          dataIndex: "carbonData",
          align: "center",
        },
        {
          title: this.$t('message.Emission_factor_unit'),
          dataIndex: "carbonMolecule",
          align: "center",
          scopedSlots: {customRender: "carbonMolecule"},
        },
        {
          title: this.$t('message.Active_data_unit'),
          dataIndex: "dataUnitText",
          align: "center",
        },
        {
          title: this.$t('message.Handle'),
          align: "center",
          dataIndex: "operation",
          scopedSlots: {customRender: "operation"},
        },{
          title: this.$t('message.Informant'),
          align: "center",
          dataIndex: "informant",
          scopedSlots: {customRender: "informant"},
        },
      ],
      columns1: [
        {
          title: this.$t('message.Emission_source'),
          dataIndex: "name",
          align: "center",
        },
        {
          title: this.$t('message.facilities_activities'),
          dataIndex: "activitieId_dictText",
          align: "center",
        },
        {
          title: this.$t('message.Emission_type'),
          dataIndex: "type_dictText",
          align: "center",
          scopedSlots: {customRender: "typeText"},
        },
        {
          title: `CO₂e${this.$t('message.Emission_factor_value')}`,
          dataIndex: "carbonData",
          align: "center",
        },
        {
          title: this.$t('message.Emission_factor_unit'),
          dataIndex: "carbonMolecule",
          scopedSlots: {customRender: "carbonMolecule"},
          align: "center",
        },
        {
          title: this.$t('message.Handle'),
          align: "center",
          dataIndex: "operation",
          scopedSlots: {customRender: "operation"},
        },
      ],
      columns2: [
        {
          title: this.$t('message.template_name'),
          dataIndex: "name",
          align: "center",
        },
        {
          title: this.$t('message.Accounting_standard'),
          dataIndex: "standardId_dictText",
          align: "center",
        },
        {
          title: this.$t('message.industry'),
          dataIndex: "profession_dictText",
          align: "center",
        },
        {
          title: this.$t('message.Source'),
          dataIndex: "type",
          scopedSlots: {customRender: "type"},
          align: "center",
        },
      ],
      selectedRowKeys: [],
      selected: [],
      selectedObje: [],
      data: [],
      listData1: [],
      data2: [],
      provinceData: [],
      professionData: [],
      basicDrawerVisible: false,
      basicCheckDetailEditVisible: false,
      basicDrawerList: {},
      basicCheckDetailEditDrawerList: {},
      basicDrawerString: "",
      basicCheckDetailEditString: "",
      form1: {},
      pagination1: {
        current: 1,
        pageSize: 10,
        pageSizeOptions: ["10", "20", "30"],
        showTotal: (total, range) => {
          return range[0] + "-" + range[1] + " 共" + total + "条";
        },
        showQuickJumper: true,
        showSizeChanger: true,
        total: 0,
      },
      form2: {},
      pagination2: {
        current: 1,
        pageSize: 10,
        pageSizeOptions: ["10", "20", "30"],
        showTotal: (total, range) => {
          return range[0] + "-" + range[1] + " 共" + total + "条";
        },
        showQuickJumper: true,
        showSizeChanger: true,
        total: 0,
      },
      form: {
        name: "",
        targetId: undefined,
        codes: undefined,
        codesName: undefined,
        profession: undefined,
      },
      rules: {
        name: [{required: true, message: this.$t('message.please_fill_in_the_template_name'), trigger: "blur"}],
      },
      FromCheck: {
        standardName: "",
        profession: undefined,
      },
      emissionSourceRowKeys:[]
    };
  },
  components: {
    JSelectUserByDepModal,
    basicDrawer,
    basicCheckDetailEditDrawer,
    rapidFilling,
    componentsKanban,
  },
  mounted() {
    this.spinning = true;
    if (this.queryId) {
      this.getDetail();
    } else {
      if (this.type == 2) {
        (this.columns = [
          {
            title: this.$t('message.Emission_source'),
            dataIndex: "emissionSourceName",
            align: "center",
          },
          {
            title: this.$t('message.facilities_activities'),
            dataIndex: "activitieName",
            align: "center",
          },
          {
            title: this.$t('message.Emission_type'),
            dataIndex: "typeText",
            align: "center",
            scopedSlots: {customRender: "typeText"},
          },
          {
            title: `CO₂e${this.$t('message.Emission_factor_value')}`,
            dataIndex: "carbonData",
            align: "center",
          },
          {
            title: this.$t('message.Emission_factor_unit'),
            dataIndex: "carbonMolecule",
            align: "center",
            scopedSlots: {customRender: "carbonMolecule"},
          },
          {
            title: this.$t('message.Active_data'),
            dataIndex: "data",
            align: "center",
            width: 150,
            scopedSlots: {customRender: "data"},
          },
          {
            title: this.$t('message.Active_data_unit'),
            dataIndex: "dataUnitText",
            align: "center",
          },
          {
            title: this.$t('message.Attachment'),
            align: "center",
            dataIndex: "dataVoucher",
            scopedSlots: {customRender: "dataVoucher"},
          },
          {
            title: this.$t('message.Handle'),
            align: "center",
            dataIndex: "operation",
            scopedSlots: {customRender: "operation"},
          },
          {
            title: this.$t('message.Informant'),
            align: "center",
            dataIndex: "informant",
            scopedSlots: {customRender: "informant"},
          },
        ]),
            (this.form.codeId = this.newForm.standardId);
        this.loadTreeRoot(1);
        this.OfCostCalcSaveUpdate();
      } else {
        // 核算下拉框
        this.loadTreeRoot();
      }
    }
    // 所属行业
    this.loadTreeRootBoSiess();
  },
  methods: {
    ...mapGetters(["userInfo"]),
    getContainer() {
      return document.getElementById("risgtUd");
    },
    handleAnchorCliack(e, link) {
      console.log(e, link);
      e.preventDefault()
      let srcolls = document.getElementById(link.href)
      srcolls.scrollIntoView({
        behavior: "smooth",
        block: 'center'
      })
    },
    onRapoidBack() {
      this.isShowDetailPopup = false;
      this.getDetailTree();
    },
    onKanbanBack() {
      this.kanbanIsAss = false;
    },
    // 数据核算
    onAccounting() {
      getAction("/orgCheckCheck/submit", {
        id: this.newForm.checkId,
      }).then((res) => {
        if (res.success) {
          this.twoType = 2;
          this.kanbanIsAss = true;
        } else {
          this.$message.error(res.message);
        }
      });
    },
    // 详情浏览
    onDetails() {
      this.kanbanIsAss = true;
      this.twoType = 1;
    },
    // 核算时间选择
    onPrnYerOpenlChange(status) {
      this.oprnYerOpen = status;
    },
    newFormpanelChange(value) {
      this.form.year = value;
      this.oprnYerOpen = false;
    },
    /**
     * 碳排放量统计部分
     */
    carbonCheckSubmitData(value) {
      getAction("/orgCheckCheck/carbonCheckSubmitData", {
        id: this.newForm.checkId,
      }).then((res) => {
        if (res.success) {
          this.carbonObj = res.result;
        }
      });
    },
    /**
     * 搜索模板
     */
    onSearch() {
      this.selectTemplate(1);
    },
    /**
     * 核算主体
     */
    OfCostCalcSaveUpdate() {
      getAction("/orgDept/getOrgAllSubjectOfCostCalc", {
        name: "",
      }).then((res) => {
        if (res.success) {
          this.CostCalcArr = res.result;
          this.form.targetId = this.newForm.targetId;
          this.form.year = this.newForm.year;
        }
      });
    },
    onCloseBasicDrawerVisible() {
      this.basicDrawerVisible = false;
      this.userPageList(1);
    },
    //打开编辑弹窗
    onBasicCheckDetailEditVisible(value) {
      this.basicCheckDetailEditString = this.$t('message.Edit_emission_source');
      this.basicCheckDetailEditDrawerList = value;
      this.basicCheckDetailEditVisible = true;
    },
    onCloseBasicCheckDetailEditVisible() {
      this.basicCheckDetailEditVisible = false;
      this.getDetailTree();
    },
    /**
     * 获取模版详情
     */
    getDetail() {
      getAction("orgCheckTemplate/getDetail", {
        id: this.queryId,
      }).then((res) => {
        if (res.success) {
          if (this.isCopy) {
            this.form.name = res.result.info.name + "-" + this.$t('message.qqqqq');replica
          } else {
            this.form.name = res.result.info.name;
          }
          this.form.codesName = res.result.info.standardName;
          this.form.codeId = res.result.info.standardId;
          this.form.profession = res.result.info.name;
          this.loadTreeRoot(1);
          this.OfCostCalcSaveUpdate();
        }
      });
    },
    /**
     * 编辑设备
     */
    saveUpdate(value) {
      getAction("/orgCarbonEmissionSource/getDetail", {id: value.id}).then((res) => {
        if (res.success) {
          this.basicDrawerList = res.result;
          this.basicDrawerString = this.$t('message.edit_facilities_activities');
          this.basicDrawerVisible = true;
        }
      });
    },

    /**
     * 保存为模版
     */
    onModels() {
      this.visible1 = true;
    },

    /**
     * 保存
     */
    saveTemplate() {
      this.$refs.ruleForm.validate((valid) => {
        if (valid) {
          let data = [];
          this.collapseData.forEach((item, index) => {
            item.children.forEach((onvales, idex) => {
              if (onvales.children) {
                onvales.children.forEach((value) => {
                  data.push({
                    dataUnit: value.dataUnit,
                    divisor: value.carbonDataId,
                    emissionSourceId: value.emissionSourceId,
                    source: value.source,
                    standardId: onvales.id,
                    type: value.type,
                  });
                });
              }
            });
          });
          let info = {
            name: this.form.name,
            profession: this.form.profession,
            standardId: this.form.codeId,
            standardName: this.form.codesName,
          };
          if (this.isCopy) {
            info.id = null;
          } else {
            info.id = this.queryId;
          }

          postAction(this.saveUrl, {
            data: data,
            info: info,
          }).then((res) => {
            if (res.success) {
              this.$message.success(res.message);
              setTimeout(() => {
                this.$emit("back");
              }, 500);
            } else {
              this.$message.error(res.message)
            }
          });
        } else {
          return false;
        }
      });
    },
    /**
     * 删除
     */
    saveDelte(ide, index, isxw, value) {
      if (this.type == 1) {
        this.collapseData[ide].children[index].children.splice(isxw, 1);
      } else {
        getAction("/orgCheckCheck/deleteCommonCheckDetail", {
          ids: value.id,
        }).then((res) => {
          if (res.success) {this.$message.success(this.$t('message.delete_success'))
            this.getDetailTree();
          }
        });
      }
    },
    /**
     * 删除
     */
    deleteBatch() {
      getAction("/orgCheckCheck/deleteCommonCheckDetail", {
        ids: this.emissionSourceRowKeys.join(","),
      }).then((res) => {
        if (res.success) {this.$message.success(this.$t('message.delete_success'))
          this.emissionSourceRowKeys = [];
          this.getDetailTree();
        }
      });
    },
    /**
     * 设施-活动管理-用户列表
     */
    paginationPacheon(e) {
      this.pagination1 = e;
      this.userPageList();
    },
    /**
     * 设施-活动管理-用户列表
     */
    userPageList(e) {
      if (e == 1) {
        this.pagination1.current = 1;
      }
      let reqData = cloneObject(this.form1);
      reqData.pageNo = this.pagination1.current;
      reqData.pageSize = this.pagination1.pageSize;
      getAction("/orgCarbonEmissionSource/userPageList", reqData).then((res) => {
        if (res.success) {
          this.listData1 = res.result.records || [];
          this.pagination1.total = res.result.total;
          this.visible = true;
        }
      });
    },
    /**
     * 首次创建只获取分类详情-----模版
     */
    getDetailOnlyCategory(e) {
      getAction("/orgCheckTemplate/getDetailOnlyCategory", {
        standardId: e ? e.key : this.form.codeId,
      }).then((res) => {
        if (res.success) {
          if (this.collapseData != null) {
            let source = []
            this.collapseData.forEach((item) => {
              source = source.concat(item.children)
            })
            let target = [];
            res.result.forEach((item) => {
              target = target.concat(item.children)
            })
            source.forEach((sourceItem) => {
              if (sourceItem.convertIds && sourceItem.children) {
                target.forEach((targetItem) => {
                  if (sourceItem.convertIds.includes(targetItem.id)) {
                    targetItem.children = sourceItem.children
                  }
                })
              }
            })
            this.collapseData = res.result
          } else {
            this.collapseData = res.result || []
          }
          this.collapseData.forEach((item, index) => {
            this.activeKey.push(item.id);
          });
        }
      }).finally(() => {
        this.spinning = false
      })
    },
    /**
     * 首次创建只获取分类详情-----填报
     */
    getDetailTree(e) {
      getAction("/orgCheckCheckDetail/getDetailTree", {
        id: this.newForm.checkId,
      }).then((res) => {
        if (res.success) {
          this.collapseData = res.result || [];
          this.collapseData.forEach((item, index) => {
            this.activeKey.push(item.id);
          });
          this.carbonCheckSubmitData();
        }
      }).finally(() => {
        this.spinning = false
      })
    },
    /**
     * 模版 只获取详情
     */
    getDetails(e) {
      getAction("/orgCheckTemplateDetail/getDetails", {
        id: this.queryId,
      }).then((res) => {
        if (res.success) {
          this.collapseData = res.result || [];
          this.collapseData.forEach((item, index) => {
            this.activeKey.push(item.id);
          });
        }
      }).finally(() => {
        this.spinning = false
      })
    },
    /**
     * 核算标准树形结构
     */
    loadTreeRootTree(e) {
      getAction("/sys/category/loadTreeRoot", {
        pcode: this.provinceData[e] ? this.provinceData[e].code : this.form.codes,
        async: false,
      }).then((res) => {
        if (res.success) {
          this.treeData = res.result || [];
          if (this.queryId) {
            this.getDetails();
          } else {
            if (this.type == 1) {
              this.getDetailOnlyCategory(this.provinceData[e]);
            } else {
              this.getDetailTree();
            }
          }
          this.$forceUpdate();
        }
      });
    },
    // 切换标准
    updateProvince(e) {
      if (this.type == 2) {
        postAction("/orgCheckCheck/changeCheckTemplateId", {
          id: this.newForm.checkId,
          checkTargetId: this.form.targetId,
          standardId: this.provinceData[e].key,
          year: this.form.year,
        }).then((res) => {
          if (res.success) {
            this.form.codes = this.provinceData[e].code;
            this.form.codeId = this.provinceData[e].key;
            this.form.codesName = this.provinceData[e].title;
            this.loadTreeRootTree(e);
          } else {
            this.$message.error(res.message);
          }
        });
      } else {
        this.loadTreeRootTree(e);
      }
    },

    /**
     * 保存为末班
     */
    handleOk() {
      postAction("/orgCheckCheck/addTemplateFromCheck", {
        checkId: this.newForm.checkId,
        profession: this.FromCheck.profession,
        standardName: this.FromCheck.standardName,
      }).then((res) => {
        if (res.success) {
          this.$message.success(this.$t('message.operation_success'))
          this.onBack();
        }
      });
    },
    /**
     * 所属行业
     */
    loadTreeRootBoSiess() {
      getAction("/sys/category/loadTreeRoot", {
        pcode: "A02",
        async: true,
      }).then((res) => {
        if (res.success) {
          this.professionData = res.result || [];
        }
      });
    },
    /**
     * 核算标准
     */
    loadTreeRoot(e) {
      getAction("/sys/category/loadTreeRoot", {
        pcode: "A01",
        async: true,
      }).then((res) => {
        if (res.success) {
          this.provinceData = res.result || [];
          if (e == 1) {
            this.provinceData.forEach((item, index) => {
              if (item.key == this.form.codeId) {
                this.form.codes = item.code;
                this.form.codeId = item.key;
                this.form.codesName = item.title;
                this.loadTreeRootTree();
              }
            });
          } else {
            this.form.codes = this.provinceData[0].code;
            this.form.codeId = this.provinceData[0].key;
            this.form.codesName = this.provinceData[0].title;
            this.loadTreeRootTree();
          }
        }
      });
    },
    // 关闭
    handleCancel() {
      this.visible1 = false;
      this.visible2 = false;
    },
    // 添加设施活动
    onSubmit() {
      if (this.type == 1) {
        if (
            this.collapseData[this.valueIndex].children[this.valueChildrenIndex].children == null
        ) {
          this.collapseData[this.valueIndex].children[this.valueChildrenIndex].children = []
        }
        this.$nextTick(() => {
          let arr = null;
          this.collapseData[this.valueIndex].children[this.valueChildrenIndex].children = []
          this.selectedRowKeys.forEach((res, index) => {
            for (let j = 0; j < this.listData1.length; j++) {
              if (this.listData1[j].id == res) {
                arr = this.listData1[j]
                break
              }
            }
            this.collapseData[this.valueIndex].children[this.valueChildrenIndex].children.push({
              emissionSourceName: arr.name,
              emissionSourceId: arr.id,
              carbonDataId: arr.carbonDataId,
              carbonData: arr.carbonData,
              sourceText: arr.source_dictText,
              source: arr.source,
              typeText: arr.type_dictText,
              type: arr.type,
              dataUnitText: arr.dataUnitText,
              dataUnit: arr.dataUnit,
              carbonMolecule: arr.carbonMolecule,
              carbonDenomintor: arr.carbonDenomintor
            })
          })
        })
      } else {
        this.createNewCommonCheckDetail(true);
      }
      this.visible = false;
    },
    /**
     * 保存设备
     */
    createNewCommonCheckDetail(isSubmit) {
      postAction("/orgCheckCheck/createNewCommonCheckDetail", {
        checkId: this.newForm.checkId,
        emissionSourceIds: this.selectedRowKeys,
        standardDetailId: isSubmit ? this.collapseData[this.valueIndex].children[this.valueChildrenIndex].id : null,
      }).then((res) => {
        if (res.success) {
          if (isSubmit) {
            this.$message.success(this.$t('message.operation_success'))
          }
          this.getDetailTree();
        } else {
          this.$message.error(res.message);
        }
      });
    },
    /**
     * 活动数据添加
     */
    saveChange(value) {
      postAction("/orgCheckCheck/editCommonCheckDetail", {
        data: value.data,
        id: value.id,
      }).then((res) => {
        if (res.success) {
          this.$message.success(this.$t('message.operation_success'))
          this.getDetailTree();
        }
      });
    },
    // 表格选中
    onSelectChange(selectedRowKeys, selectedRowObje) {
      console.log(
          "selectedRowKeys changed: ",
          selectedRowKeys,
          selectedRowObje
      );
      this.selectedRowKeys = selectedRowKeys;
      this.selectedRowObje = selectedRowObje;
    },
    // 选择模版
    ontChange(selectedRowKeys, selectedObje) {
      if (selectedRowKeys.length == 1 || selectedRowKeys.length < 1) {
        console.log("selectedRowKeys changed: ", selectedRowKeys, selectedObje);
        this.selected = selectedRowKeys;
        this.selectedObje = selectedObje;
      }
    },
    // 选择模版弹窗表格分页
    onChangePage2(e) {
      this.pagination2 = e;
      this.selectTemplate();
    },
    /**
     * 确认选择模版
     */
    templateHandleOk() {
      if (this.selectedObje.length == 0) {
        this.$message.warning(this.$t('message.please_select_a_template'));
        return;
      }
      postAction("/orgCheckCheck/addDetailFromStandradId", {
        id: this.newForm.checkId,
        templateId: this.selectedObje[0].id,
      }).then((res) => {
        if (res.success) {
          this.$message.success(this.$t('message.add_success'));
          this.visible2 = false;
          this.getDetailTree();
        } else {
          this.$message.error(res.message);
        }
      });
    },
    // 新增或查看
    onBasicDrawerVisible(value) {
      if (value == 1) {
        this.basicDrawerString = this.$t('message.Add_emission_sources');
        this.basicDrawerList = {};
        this.basicDrawerVisible = true;
      }
    },
    onVsisible(index, idexs, children) {
      this.valueChildrenIndex = idexs;
      this.valueIndex = index;
      this.form1.standardDetailId = this.collapseData[this.valueIndex].children[this.valueChildrenIndex].id;
      this.selectedRowKeys = [];
      this.selectedRowObje = [];
      if (children) {
        children.forEach((item) => {
          this.selectedRowKeys.push(item.emissionSourceId);
        });
      }
      this.userPageList();
    },
    onClose() {
      this.visible = false;
    },
    onBack() {
      this.$emit("back");
    },
    // 快速填表
    onRapidFilling() {
      this.isShowDetailPopup = true;
    },
    /**
     *模版数据分页
     */
    selectTemplate(page) {
      if (page === 1) {
        this.pagination2.current = 1;
      }
      let reqData = cloneObject(this.form2);
      if (reqData.name) {
        reqData.name = `*${reqData.name}*`;
      }
      reqData.pageNo = this.pagination2.current;
      reqData.pageSize = this.pagination2.pageSize;
      getAction("/orgCheckTemplate/queryOrgPageList", reqData).then((res) => {
        if (res.success) {
          this.data2 = res.result.records || [];
          this.pagination2.total = res.result.total;
          this.visible2 = true;
        }
      });
    },
    onInviteUserVisible(informantDetailIds){
      this.informantDetailIds = informantDetailIds
      this.$refs.userSelectModal.showModal()
    },
    /*
    * 填报人修改
    *  */
    informantChange(value,recordId){

    },
    selectedUserOk(value){
      //邀请填报
      postAction("/orgCheckCheckDetail/updateInformant", {informantDetailIds:this.informantDetailIds,informantUserId:value[0].id,informantUserName:value[0].realname}).then((res) => {
        if (res.success) {
          this.$message.success(this.$t('message.operation_success'))
          this.getDetailTree();
        } else {
          this.$message.error(res.message);
        }
      })
    },
    onCancelInvite(informantDetailId){
      postAction("/orgCheckCheckDetail/updateInformant", {informantDetailIds:[informantDetailId],informantUserId:null,informantUserName:null}).then((res) => {
        if (res.success) {
          this.$message.success(this.$t('message.operation_success'))
          this.getDetailTree();
        } else {
          this.$message.error(res.message);
        }
      })
    },
    onCancelDataVoucher(informantDetailId){
      getAction("/orgCheckCheckDetail/uploadDataVoucher", {id:informantDetailId,savePath:null}).then((res) => {
        if (res.success) {
          this.$message.success(this.$t('message.operation_success'))
          this.getDetailTree();
        } else {
          this.$message.error(res.message);
        }
      })
    },
    /* 文件下载 */
    // update--autor:lvdandan-----date:20200630------for：修改下载文件方法名uploadFile改为downloadFile------
    downloadFile(text){
      if(!text){
        this.$message.warning("未知的文件")
        return;
      }
      if(text.indexOf(",")>0){
        text = text.substring(0,text.indexOf(","))
      }
      let url = getFileAccessHttpUrl(text)
      window.open(url);
    },
    emissionSourceSelected (selectedRowKeys, selectedRows) {
      this.emissionSourceRowKeys = selectedRowKeys;
    },
    onClearEmissionSourceRowKeys(){
      this.emissionSourceRowKeys = []
    }
  },
};
</script>
<style lang="less">
.table-page-tpyzd {
  .ant-form-inline {
    .ant-form-item {
      display: flex;
      margin-right: 0;

      .ant-form-item-control-wrapper {
        flex: 1 1;
        display: inline-block;
        vertical-align: middle;
      }

      > .ant-form-item-label {
        line-height: 32px;
        padding-right: 8px;
        width: auto;
      }

      .ant-form-item-control {
        height: 32px;
        line-height: 32px;
      }
    }
  }

  .table-page-search-submitButtons {
    display: block;
    white-space: nowrap;
  }
}

.collapse-tpyz {
  .ant-collapse {
    background: #fff !important;
    border: none !important;
    border-radius: 0 !important;
  }

  .ant-collapse-item {
    border: none !important;
  }

  .ant-collapse-content {
    background: #f5f7f6 !important;
  }

  .ant-collapse-content-box {
    padding: 24px 0 24px 48px !important;
  }
}
</style>

<style lang="less" scoped>
.paddTops {
}

.posts {
  position: absolute;
  left: 300px;
  top: 0;
  z-index: 9;
  width: calc(100% - 300px);
}

.wigthsP {
  width: 94px;
  height: 40px;
}

.bottom {
  width: 97.5%;
  padding: 0px 24px;
  height: 80px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-top: 1px solid #e7e7e7;
  background: #ffffff;
  position: fixed;
  bottom: 24px;

  .bottom-flex {
    display: flex;
    align-items: baseline;
  }

  .text {
    font-weight: 400;
    font-size: 18px;
    color: #333333;
  }

  .text1 {
    font-weight: 500;
    font-size: 32px;
    color: #148958;
    margin-right: 14px;
  }

  .text2 {
    font-weight: 400;
    font-size: 22px;
    color: #148958;
  }

  .text3 {
    font-weight: 400;
    font-size: 16px;
    color: #333333;
  }

  .text4 {
    font-weight: 500;
    margin-right: 14px;
    font-size: 18px;
    color: 333333;
  }

  .text5 {
    font-weight: 400;
    font-size: 16px;
    color: 333333;
  }
}

/deep/ .ant-drawer-wrapper-body {
  padding: 24px 0 56px 0 !important;
}

.flex1 {
  display: flex;
  align-items: center;
  gap: 24px;
}

.flex2 {
  display: flex;
  align-items: baseline;
  gap: 54px;
}

.marbot {
  margin-bottom: 24px;
}

.flex {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.centers {
  display: flex;
  flex-direction: column;
}

.contentBox {
  margin-top: 24px;
  display: flex;
  // height: 94%;
  flex: 1;
  position: relative;
}

.paddings {
  padding-bottom: 80px;
}

.collaose-center {
  margin-bottom: 24px;

  .collaose-title {
    display: flex;
    align-items: center;
    font-weight: 400;
    font-size: 14px;
    color: rgba(0, 0, 0, 0.9);
    margin-bottom: 14px;

    img {
      width: 16px;
      height: 16px;
      margin-right: 8px;
    }
  }

  .collapse-table {
    margin-bottom: 14px;
  }

  .collapse-tian {
    border-radius: 3px 3px 3px 3px;
    border: 1px solid #148958;
    font-weight: 400;
    font-size: 12px;
    color: #148958;
    padding: 2px 8px;
    background: #ffffff;
    display: flex;
    align-items: center;

    img {
      width: 14px;
      height: 14px;
    }
  }
}

.xinzeng {
  border-radius: 3px 3px 3px 3px;
  border: 1px solid #148958;
  font-weight: 400;
  font-size: 14px;
  color: #148958;
  padding: 5px 16px;
  background: #ffffff;
  display: flex;
  align-items: center;

  img {
    width: 16px;
    height: 16px;
  }
}

.collapse-tpyz {
  margin-top: 16px;
}

.img {
  width: 16px;
  height: 16px;
  margin-right: 10px;
}

.leftChaxun {
  background: #148958 !important;
  color: #fff !important;
}

.top {
  background: #ffffff;
  border-radius: 3px 3px 3px 3px;
  padding: 12px 24px;
}

.rightTree {
  flex: 1;
  padding-top: 60px;
}

.scroll {
  overflow-y: scroll;
}

.leftTree {
  width: 300px;
  background: #fff;
  padding: 29px 25px;
  overflow-y: scroll;
  border-right: 1px solid #e7e7e7;

  .select {
    margin-bottom: 24px;
  }

  /deep/ .ant-dropdown-trigger {
    width: 200px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: inline-block;
    // max-length:200px;
  }
}

.cardHeader {
  font-family: PingFang SC, PingFang SC;
  font-weight: 400;
  font-size: 14px;
  color: #000000;

  .cardHeader_icon {
    width: 16px;
    height: 16px;
  }
}
.information{
  display: flex;
  align-items: center;
  justify-content: center;
  img{
    display: block;
    transform: translateY(2px);
  }
}
.ant-alert {
}

</style>
